package com.webdemo03.action;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.opensymphony.xwork2.ActionSupport;
import com.webdemo03.bean.User;
import com.webdemo03.util.DBHandler;

public class AddUser extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private User user;
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		Connection conn = DBHandler.newInstance().getConnection();
		String sql = "insert into xml02_user(id,name) values(?,?)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1, user.getId());
		pstmt.setString(2, user.getName());
		pstmt.executeUpdate();
		return "show";
	}
	
}
